package com.yuntcm.group6.med_booking.controller;

import com.yuntcm.group6.med_booking.entity.Schedule;
import com.yuntcm.group6.med_booking.service.ScheduleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/schedule")
public class ScheduleController {

    @Autowired
    private ScheduleService scheduleService;

    // 获取所有排班信息
    @GetMapping
    public List<Schedule> scheduleList() {
        return scheduleService.list();
    }

    // 根据医生 ID 获取排班信息
    @GetMapping("/doctor/{doctorId}")
    public List<Schedule> scheduleListByDoctorId(@PathVariable Integer doctorId) {
        return scheduleService.listByDoctorId(doctorId);
    }

    // 更新排班信息
    @PostMapping("/update")
    public boolean updateSchedule(@RequestBody Schedule schedule) {
        return scheduleService.updateById(schedule);
    }

    // 删除排班信息
    @DeleteMapping("/delete/{id}")
    public boolean deleteScheduleById(@PathVariable Integer id) {
        return scheduleService.removeById(id);
    }

    // 添加排班信息
    @PostMapping("/add")
    public boolean addSchedule(@RequestBody Schedule schedule) {
        return scheduleService.save(schedule);
    }
}